﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
using System.Globalization;
using System.Web.Security;

namespace Bordspil.Models
{
    public class UsersContext : DbContext
    {
        public UsersContext()
            : base("AppDataContext")
        {
        }

        public DbSet<UserProfile> UserProfiles { get; set; }
    }

    [Table("UserProfile")]
    public class UserProfile
    {
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int UserId { get; set; }
        public string UserName { get; set; }
        public string Email { get; set; }
        public int Age { get; set; }
        public byte[] UserPicture { get; set; }
    }

    public class RegisterExternalLoginModel
    {
        [Required]
        [Display(Name = "Notendanafn")]
        public string UserName { get; set; }

        public string ExternalLoginData { get; set; }
    }

    public class LocalPasswordModel
    {
        [Required]
        [DataType(DataType.Password)]
        [Display(Name = "Núverandi Lykilorð")]
        public string OldPassword { get; set; }

        [Required]
        [StringLength(100, ErrorMessage = "{0} þarf að vera að lágmarki {2} stafa langt", MinimumLength = 6)]
        [DataType(DataType.Password)]
        [Display(Name = "Nýtt Lykilorð")]
        public string NewPassword { get; set; }

        [DataType(DataType.Password)]
        [Display(Name = "Staðfesta nýtt Lykilorð")]
        [Compare("NewPassword", ErrorMessage = "Nýja Lykilorðið og staðfest Lykilorð passa ekki!")]
        public string ConfirmPassword { get; set; }
    }

    public class LoginModel
    {
        [Required]
        [Display(Name = "Notendanafn")]
        public string UserName { get; set; }

        [Required]
        [DataType(DataType.Password)]
        [Display(Name = "Lykilorð")]
        public string Password { get; set; }

        [Display(Name = "Muna eftir mér?")]
        public bool RememberMe { get; set; }
    }

    public class RegisterModel
    {
        [Required(ErrorMessage = "Vinsamlegast sláðu inn notendanafn")]
        [Display(Name = "Notendanafn")]
        public string UserName { get; set; }

        [Required(ErrorMessage = "Vinsamlegast sláðu inn netfang")]
        [Display(Name = "Netfang")]
        [EmailValidation(ErrorMessage = "Vinsamlegast sláðu inn löglegt netfang")]
        public string Email { get; set; }

        [Required(ErrorMessage = "Vinsamlegast sláðu inn lykilorð")]
        [StringLength(100, ErrorMessage = "Lykilorðið þarf að vera minnst {2} stafa langt", MinimumLength = 6)]
        [DataType(DataType.Password)]
        [Display(Name = "Lykilorð")]
        public string Password { get; set; }

        [DataType(DataType.Password)]
        [Display(Name = "Staðfesta lykilorð")]
        [Compare("Password", ErrorMessage = "Lykilorðið og staðfest Lykilorð passa ekki!")]
        public string ConfirmPassword { get; set; }

        [Required(ErrorMessage = "Vinsamlegast sláðu inn aldur")]
        [Display(Name = "Aldur")]
        [Range(1, 3000, ErrorMessage = "Aldur þarf að vera á bilinu 1-3000")]
        public int Age { get; set; }

    }

    public class ExternalLogin
    {
        public string Provider { get; set; }
        public string ProviderDisplayName { get; set; }
        public string ProviderUserId { get; set; }
    }

    public class EmailValidationAttribute : RegularExpressionAttribute
    {
        public EmailValidationAttribute() 
        : base("[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?")
        {
        }
    }
}
